package com.ihrm.company.service.impl;

import com.ihrm.common.service.BaseService;
import com.ihrm.common.utils.IdWorker;
import com.ihrm.company.dao.DepartmentDao;
import com.ihrm.company.service.DepartmentService;
import com.ihrm.domain.company.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 小伟
 * @version V1.0
 * @Package com.ihrm.company.service.impl
 * @date 2020/12/11 21:29
 * @Copyright © 2020-2021 郑州恒星科技有限责任公司
 */
@Service
public class DepartmentServiceImpl extends BaseService<DepartmentServiceImpl> implements DepartmentService {
    /**
     * 注入dao接口
     */
    @Autowired
    DepartmentDao departmentDao;
    /**
     * 注入生成工具id类
     */
    @Autowired
    IdWorker idWorker;

    /**
     * 添加部门信息
     *
     * @param department 部门对象
     */
    @Override
    public void saveDepartment(Department department) {
        String id = idWorker.nextId() + "";
        department.setId(id);
        departmentDao.save(department);
    }

    /**
     * 修改部门信息
     *
     * @param department 部门对象
     */
    @Override
    public void updateDepartment(Department department) {
        departmentDao.save(department);

    }

    /**
     * 根据id查询部门信息
     *
     * @param id 部门id
     * @return 部门信息
     */
    @Override
    public Department findById(String id) {
        return departmentDao.findById(id).get();
    }

    /**
     * 查询企业全部部门信息
     *
     * @param comanyId 企业ID
     * @return 部门列表
     */
    @Override
    public List<Department> findAllByCompanyId(String comanyId) {
        return departmentDao.findAll(getSpecification(comanyId));
    }

    /**
     * 根据部门id删除部门
     *
     * @param id 部门id
     */
    @Override
    public void deleteById(String id) {
        departmentDao.deleteById(id);
    }

    /**
     * 根据部门编号和企业id查询部门信息
     *
     * @param code      部门编号
     * @param companyId 企业id
     * @return 部门对象
     */
    @Override
    public Department findByCodeAndCompanyId(String code, String companyId) {
        return departmentDao.findByCodeAndCompanyId(code, companyId);
    }
}
